package com.chinaso.kotlinprojcet.ui

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.Button
import android.widget.Toast
import com.chinaso.kotlinprojcet.R

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        initMainView()

    }

    private fun initMainView() {
        val btn = findViewById<Button>(R.id.button01) as Button
        btn.text = getString(R.string.switch_newpage_session)
        btn.setOnClickListener(SwitchActivityOnClick())

        val btnList = findViewById<Button>(R.id.btnList) as Button
        btnList.text = "跳转到列表RecyclerView页面"
        btnList.setOnClickListener { startActivity(Intent(this, RecyclerActivity::class.java)) }
    }

    private inner class SwitchActivityOnClick : View.OnClickListener {
        override fun onClick(view: View) {
            startActivity(Intent(view.context, SecondActivity::class.java))
        }
    }

    override fun onBackPressed() {
        super.onBackPressed()

        back()
    }

    private fun back(){
        Toast.makeText(this, "tiaochu", Toast.LENGTH_LONG).show();
        finish()
    }
}
